
//����������
package com.creawor.hz_market.t_advertisement;
import java.util.Iterator;
import java.util.List;

import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Query;

import com.creawor.imei.base.AbsQueryMap;

public class t_advertisement_QueryMap extends AbsQueryMap {

public t_advertisement_QueryMap() throws HibernateException {
	this.initSession();
}

public Iterator findAll() throws HibernateException {
	this.totalrow =	((Integer) this.session.iterate("select count(*) from t_advertisement").next()).intValue();
	String querystr = "from t_advertisement";
	Query query = this.session.createQuery(querystr);
    this.setQueryPage(query);
	return query.iterate();
}
public List findAllList() throws HibernateException {
	this.totalrow =	((Integer) this.session.iterate("select count(*) from t_advertisement").next()).intValue();
	String querystr = "from t_advertisement";
	Query query = this.session.createQuery(querystr);
    this.setQueryPage(query);
	return query.list();
}

public List findAllByCounty(String county) throws HibernateException {
	this.totalrow =	((Integer) this.session.iterate("select count(*) from t_advertisement where county ='"+county+"'").next()).intValue();
	String querystr = "from t_advertisement  as t where t.county ='"+county+"'";
	Query query = this.session.createQuery(querystr);
    this.setQueryPage(query); 
	return query.list();
}

public List findAllByCountyshi() throws HibernateException {
	this.totalrow =	((Integer) this.session.iterate("select count(*) from t_advertisement").next()).intValue();
	String querystr = "from t_advertisement";
	Query query = this.session.createQuery(querystr);
    this.setQueryPage(query);
	return query.list();
}

public List findByCode(String code) throws HibernateException {
	
	String querystr = "from t_advertisement mode where mode.advertiserment_code=?";
	Query query = this.session.createQuery(querystr);
	query.setParameter(0, code);
    this.setQueryPage(query);
	return query.list();
}
public t_advertisement_Form getByID(String ID) throws HibernateException {
t_advertisement_Form  vo = null;

  //System.out.println("\nt_advertisement_QueryMap getByID:"+ID);

	this.session.clear();
	try {
		vo =new t_advertisement_Form();
		t_advertisement po=(t_advertisement) this.session.load(t_advertisement.class, new Integer(ID));

  try{
    vo.setId(String.valueOf(po.getId()));
  }catch (Exception e) {
	    e.printStackTrace();
  }
  vo.setAdvertiserment_code(po.getAdvertiserment_code());
  vo.setAdvertisement_type(po.getAdvertisement_type());
  vo.setRelease_form(po.getRelease_form());
  vo.setPicture(po.getPicture());
  vo.setThe_content(po.getThe_content());
  vo.setSpecification(po.getSpecification());
  vo.setCounty(po.getCounty());
  vo.setAdvertiserment_name(po.getAdvertiserment_name());
  vo.setCompany(po.getCompany());
  vo.setContract_code(po.getContract_code());
  vo.setContract_sum(po.getContract_sum());
  vo.setTown(po.getTown());

  try{
    vo.setCreatedtime(com.creawor.km.util.DateUtil.getStr(po.getCreatedtime(),"yyyy-MM-dd"));
  }catch (Exception e) {
	    e.printStackTrace();
  }

  try{
    vo.setPublishdate(com.creawor.km.util.DateUtil.getStr(po.getPublishdate(),"yyyy-MM-dd"));
  }catch (Exception e) {
	    e.printStackTrace();
  }

  try{
    vo.setDeadline(com.creawor.km.util.DateUtil.getStr(po.getDeadline(),"yyyy-MM-dd"));
    vo.setUpdated_day(com.creawor.km.util.DateUtil.getStr(po.getUpdated_day(),"yyyy-MM-dd"));
  }catch (Exception e) {
	    e.printStackTrace();
  }
  vo.setVendor(po.getVendor());
  vo.setAddress(po.getAddress());

  try{
    vo.setX(String.valueOf((po.getX())));
  }catch (Exception e) {
    	e.printStackTrace();
  }

  try{
    vo.setY(String.valueOf((po.getY())));
  }catch (Exception e) {
    	e.printStackTrace();
  }
  vo.setCompany(po.getCompany());
	} catch (HibernateException e) {
		//System.out.println("\nERROR in getByID @t_advertisement:" + e);
	}
	return vo;
}	

}
//����������
